#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>

void swap(char* buf1, char* buf2,int width)
{
	char tmp = 0;
	for (int i = 0; i < width; i++)
	{
		tmp = *buf1;
		*buf1 = *buf2;
		*buf2 = tmp;
		buf1++;
		buf2++;
	}
}

int int_cmp(const void* e1, const void* e2)
{
	return *(int*)e1 - *(int*)e2;
}

int char_cmp(const void* e1, const void* e2)
{
	return strcmp(*(char*)e1, *(char*)e2);
}

void My_qsort(void* base, int sz, int width, int (*cmp)(const void* e1,const void* e2))
{
	for (int i = 0; i < sz - 1; i++)
	{
		for (int j = 0; j < sz - 1 - i; j++)
		{
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width) > 0)
			{  
				swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}

void print_arr(int* arr, int sz)
{
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
}

int main()
{
	int arr[] = { 8,0,6,9,7,2,4,1,3,5 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	My_qsort(arr, sz, sizeof(arr[0]), int_cmp);
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}